//package com.breakfast.fun.base;
//
//import android.app.Dialog;
//import android.content.Context;
//import android.os.Bundle;
//import android.support.annotation.Nullable;
//import android.support.v7.app.AppCompatActivity;
//import android.view.WindowManager;
//
//import com.breakfast.fun.App;
//import com.breakfast.fun.util.CartAnimUtil;
//import com.breakfast.fun.util.DialogUtil;
//import com.breakfast.fun.util.ImageUtil;
//import com.breakfast.fun.util.StatusBarUtil;
//import com.breakfast.fun.util.TUtil;
//import com.google.android.gms.analytics.HitBuilders;
//import com.google.android.gms.analytics.Tracker;
//
//import butterknife.ButterKnife;
//
///**
// * Created by hp on 2016/8/13.
// */
//public abstract class BaseActivity<P extends BasePresenter,M extends BaseModel> extends AppCompatActivity {
//    public P presenter;
//    public M model;
//
//    public Context context;
//
//    protected DialogUtil mDialogUtil;
//    protected Dialog mDialog;
//
//    protected ImageUtil imageUtil;
//
//    protected Tracker mTracker;
//
//    protected CartAnimUtil mCartAnimUtil;
//
//
//    @Override
//    protected void onCreate(@Nullable Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//
//
//        this.setContentView(this.getLayoutId());
//        StatusBarUtil.transparent(getWindow());
//        ButterKnife.bind(this);
//        context = this;
//        imageUtil = new ImageUtil(this);
//        mDialogUtil = new DialogUtil(this);
//        mCartAnimUtil = new CartAnimUtil(this);
//        presenter = TUtil.getT(this,0);
//        model = TUtil.getT(this,1);
//        mTracker = App.getApp().getDefaultTracker();
//        //mTracker.setScreenName(AnalyticsUtil.translateClassName(this.getClass().getSimpleName()));
//        this.initView();
//        if(this instanceof BaseView) presenter.setVM(context,this,model);
//    }
//
//    protected void showLoadingDialog(boolean isCanClose) {
//        if (mDialog != null) {
//            if (mDialog.isShowing()) {
//                mDialog.dismiss();
//            }
//        }
//        mDialog = mDialogUtil.getWaitDialog("加载中...", isCanClose);
//    }
//
//    protected void hideLoadingDialog() {
//        if (mDialog != null) {
//            if (mDialog.isShowing()) {
//                mDialog.dismiss();
//            }
//        }
//    }
//
//    @Override
//    protected void onDestroy() {
//        super.onDestroy();
//        if(presenter != null){
//            presenter.onDestroy();
//        }
//        ButterKnife.unbind(this);
//        destroyView();
//    }
//
//    /**
//     * 设置添加屏幕的背景透明度
//     * @param bgAlpha
//     */
//    public void backgroundAlpha(float bgAlpha)
//    {
//        WindowManager.LayoutParams lp = getWindow().getAttributes();
//        lp.alpha = bgAlpha; //0.0-1.0
//        getWindow().setAttributes(lp);
//    }
//
//    @Override
//    protected void onResume() {
//        super.onResume();
//        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
//    }
//
//    protected void destroyView(){
//
//    }
//
//    public abstract int getLayoutId();
//
//    public abstract void initView();
//
//    public BaseActivity() {
//    }
//}


package com.breakfast.fun.base;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;

import com.breakfast.fun.App;
import com.breakfast.fun.util.CartAnimUtil;
import com.breakfast.fun.util.DialogUtil;
import com.breakfast.fun.util.ImageUtil;
import com.breakfast.fun.util.StatusBarUtil;
import com.breakfast.fun.util.TUtil;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;

import butterknife.ButterKnife;

/**
 * Created by hp on 2016/8/13.
 */
public abstract class BaseActivity<P extends BasePresenter, M extends BaseModel> extends AppCompatActivity {
    public P presenter;
    public M model;

    public Context context;

    protected DialogUtil mDialogUtil;
    protected Dialog mDialog;

    protected ImageUtil imageUtil;

    protected Tracker mTracker;
    protected CartAnimUtil mCartAnimUtil;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(this.getLayoutId());
        StatusBarUtil.transparent(getWindow());
        ButterKnife.bind(this);
        context = this;
        imageUtil = new ImageUtil(this);
        mDialogUtil = new DialogUtil(this);
        presenter = TUtil.getT(this, 0);
        model = TUtil.getT(this, 1);
        mCartAnimUtil = new CartAnimUtil(this);
        mTracker = App.getApp().getDefaultTracker();
        //mTracker.setScreenName(AnalyticsUtil.translateClassName(this.getClass().getSimpleName()));
        this.initView();
        if (this instanceof BaseView) presenter.setVM(context, this, model);
    }

    protected void showLoadingDialog(boolean isCanClose) {
        if (mDialog != null) {
            if (mDialog.isShowing()) {
                mDialog.dismiss();
            }
        }
        mDialog = mDialogUtil.getWaitDialog("加载中...", isCanClose);
    }

    protected void hideLoadingDialog() {
        if (mDialog != null) {
            if (mDialog.isShowing()) {
                mDialog.dismiss();
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (presenter != null) {
            presenter.onDestroy();
        }
        ButterKnife.unbind(this);
        destroyView();
    }

    /**
     * 设置添加屏幕的背景透明度
     *
     * @param bgAlpha
     */
    public void backgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.alpha = bgAlpha; //0.0-1.0
        getWindow().setAttributes(lp);
    }

    @Override
    protected void onResume() {
        super.onResume();
        mTracker.send(new HitBuilders.ScreenViewBuilder().build());
    }

    protected void destroyView() {

    }

    public abstract int getLayoutId();

    public abstract void initView();


}
